
*directory to be changed 
 cd "/Users/eliemurard/Dropbox/immigration welfare attitudes-Freeman/dofile_1718/replication JEG/"

	
	
	use "replication_data_JEG.dta", clear 
	
	
	keep if ess_sample ==1	
	keep if sample_Z_pca_score  ==1  
 


		
******************************************************************************************************************************  	
****     Table A.4 
******************************************************************************************************************************  	
	
	ta name_country  , gen(ncountry__)
	ta year_ess  , gen(year_ess__)
 
	global dependent   Z_pca_score 	Z_redis_scale   Z_support_incequal     Z_gvslvol Z_gvslvue Z_gvcldcr Z_sbstrec   Z_sbbsntx Z_sblazy  
	global immivar  pct_1990 pct_2000  pct_2010    year_ess__*  ncountry__* 
	
	
 	eststo clear
	qui eststo stat :   estpost tabstat   $dependent $immivar     ,  statistics(mean sd min max) columns(statistics) 
	nois esttab stat  , title(Table A.4) label  cells( "mean sd min max" )   nonumbers noeqlines smcl width(200%) 	nodepvars   nonotes 
		
******************************************************************************************************************************  	
****     Table A.5
******************************************************************************************************************************  	
	
	
	 global CONTROL_regional  ln_pop_nat_value ln_gdp_PPP_percap unemp2064 ln_N_skill_ratio
	 global CONTROL_indiv     male coh_*  edulvla__*   immi_eu immi_noeu parent_immi_eu parent_immi_noeu edu_parents_2 edu_parents_3 edu_parents_4  miss_eduparents ///
					     nb_child nb_adu nb_elder  domicil2 domicil3 domicil4 domicil5  ///
					   self_employed hswrk edctn uempla uempli dsbld rtrd  
	global CONTROL_income         isco88_2d quant_hhincome  hincfel		
	global CONTROL_subview   ipeqopt iphlppl  lrscale pplfair 
	global robust	capitals federation	ln_import_shock07_91 ln_bed_percap2010_2015  GDP_growth_80_00    GDP_growth_65_00 ln_import_shock07_91  manufacturing_share   ln_riskpoverty ln_bed_percap2010_2015 
	global hetero  high_welfarestate  leftist immi_bad_life  immi_NOrightsoc ///
			pct_EU15_2010    pct_A10_2010    pct_MiddleEast_2010   pct_Africa_2010  pct_America_2010  pct_Asia_2010  ///
		 ln_rsc_mayda ln_rsc_topoccu flow_2000_90    flow_2010_00 dissi_index
 
 	
		eststo clear
qui eststo stat :   estpost tabstat $CONTROL_regional   $CONTROL_indiv  $CONTROL_income   $CONTROL_subview    $robust $hetero    , statistics(mean sd min max) columns(statistics) 
	nois esttab   stat , title(Table A.5)  label  cells( "mean sd min max" )   nonumbers noeqlines smcl width(200%) 	nodepvars   nonotes 
	
	
	
******************************************************************************************************************************  	
****   SET-UP
******************************************************************************************************************************  	
	
	 global option varlabels tex plain fragment bdec(3) se starloc(1) starlevels(10 5 1) nocenter 
		
	 global regional  ln_pop_nat_value ln_gdp_PPP_percap unemp2064 ln_N_skill_ratio
	
	 global controlindiv     male coh_*  edulvla__*   immi_eu immi_noeu parent_immi_eu parent_immi_noeu edu_parents_2 edu_parents_3 edu_parents_4  miss_eduparents ///
					     nb_child nb_adu nb_elder  domicil2 domicil3 domicil4 domicil5  ///
					   self_employed hswrk edctn uempla uempli dsbld rtrd  
	
    global control   i.coh#i.male   i.male#i.edulvla   immi_eu immi_noeu parent_immi_eu parent_immi_noeu edu_parents_2 edu_parents_3 edu_parents_4  miss_eduparents ///
					     nb_child nb_adu nb_elder  domicil2 domicil3 domicil4 domicil5  ///
					   self_employed hswrk edctn uempla uempli dsbld rtrd  
					   
	global inc_control  i.isco88_2d i.quant_hhincome  i.hincfel		
	global subview_control     i.ipeqopt  i.iphlppl  i.lrscale i.pplfair 

	global option varlabels tex plain fragment bdec(3) se starloc(1) starlevels(10 5 1) nocenter  
   
	global model_1   "Country-year FE", "X" \ "Regional control", "" \ "Basic Indiv-controls", "" \ "Income controls", "" \ "Ideology controls", ""   
	global model_2	 "Country-year FE", "X"  \ "Regional control", "X" \ "Basic Indiv-controls", "" \ "Income controls", "" \ "Ideology controls", ""  
	global model_3	 "Country-year FE", "X"  \ "Regional control", "X" \ "Basic Indiv-controls", "X" \ "Income controls", "" \ "Ideology controls", ""     
	global model_4   "Country-year FE", "X"  \ "Regional control", "X" \ "Basic Indiv-controls", "X" \ "Income controls", "X" \ "Ideology controls", ""    
	global model_5	 "Country-year FE", "X"  \ "Regional control", "X" \ "Basic Indiv-controls", "X" \ "Income controls", "X" \ "Ideology controls", "X"    

	
	global Z_dependent	  Z_pca_score 
	global Z_dep_robust  	Z_redis_scale   Z_support_incequal     Z_gvslvol Z_gvslvue Z_gvcldcr Z_sbstrec   Z_sbbsntx Z_sblazy  

	
	global  m2010_qua pct_2010  pct_2010_sq
	
	global  m2000_qua pct_2000  pct_2000_sq
	
	global  m1990_qua pct_1990  pct_1990_sq
	
	capt program drop breakpoint_2010_qua 
	program define breakpoint_2010_qua  
	global  breakpoint = -(_b[pct_2010] /(2* _b[pct_2010_sq]))
	global  breakpoint = round($breakpoint, 0.001) 
	end
	capt program drop breakpoint_2000_qua
	program define breakpoint_2000_qua 
	global  breakpoint = -(_b[pct_2000] /(2* _b[pct_2000_sq]))
	global breakpoint = round($breakpoint, 0.001) 
	end
	capt program drop breakpoint_1990_qua 
	program define breakpoint_1990_qua  
	global  breakpoint = -(_b[pct_1990] /(2* _b[pct_1990_sq]))
	global  breakpoint = round($breakpoint, 0.001) 
	end
	
******************************************************************************************************************************  	
****   Table A.6: Robustness Checks: Census years in which immigrant stocks are measured
******************************************************************************************************************************  	


foreach y in Z_pca_score     {
	
	local l  :  variable label `y'
	dis "`l'"
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	qui su `y'    if   `samplee'==1  
	local av = round(r(mean),0.01) 
 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	
		
	foreach j in 1990_qua 2000_qua {
		
	outreg, clear(robust_`j')
 	
	global m1 ${m`j'}
	
	qui `equa1' `y'    $m1      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	  breakpoint_`j'
	  qui outreg, merge(robust_`j')  	 nod keep( $m1   ) ctitle("`l'", "")  ${option} addrows( "$model_1" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'    $m1  $regional      if   `samplee'==1 ,     `equa2' vce(cluster id_nuts2)
	  breakpoint_`j'
	   qui outreg, merge(robust_`j')  	 nod keep( $m1   ) ctitle("`l'", "")   ${option}  addrows( "$model_2" \ "breakpoint", $breakpoint ) 
		
	qui  `equa1' `y'    $m1  $regional $control     if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	  breakpoint_`j'
	  outreg, merge(robust_`j')  	 nod keep( $m1   ) ctitle("`l'", "")  ${option}  addrows( "$model_3" \ "breakpoint", $breakpoint ) 
	
	qui  `equa1' `y'  $m1  $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	  breakpoint_`j'
	   qui outreg, merge(robust_`j')  	 nod keep( $m1   ) ctitle("`l'", "")   ${option} addrows( "$model_4" \ "breakpoint", $breakpoint ) 
	
	qui  `equa1' `y'  $m1   $regional $control $inc_control  $subview_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	  breakpoint_`j'
	  qui  outreg, merge(robust_`j')  	 nod keep( $m1   ) ctitle("`l'", "")  ${option}  addrows( "$model_5" \ "breakpoint", $breakpoint ) 
	
	}
	*
	}
	*
	nois outreg , replay(robust_1990_qua)   $option     title(Table A.6)
	nois outreg , replay(robust_2000_qua)   $option     title(Table A.6)
  
	
******************************************************************************************************************************  	
***  Table A.7: First-Stage of Shift-Share instrument 
******************************************************************************************************************************  	
 	   	
	cap drop pct_IV_2010_sq 
	g  pct_IV_2010_sq=  pct_IV_2010^2 
	
	global  m2010_lin pct_2010 
	global  m2010_qua pct_2010  pct_2010_sq
	
	global  IV_qua  pct_IV_2010  pct_IV_2010_sq
	
	label var pct_IV_2010 "Predicted sh.immi 2010"
	label var pct_IV_2010_sq "Predicted sh.immi 2010, squared"
			
     outreg, clear(IV_FIRST)
	
	local l  :  variable label pct_2010   
	
	qui  reg pct_2010    ${IV_qua}  i.id_country_yearess  $regional $control     if   sample_Z_pca_score ==1 , cluster (id_nuts2)
	test ${IV_qua} 
	local F = round( r(F) ,0.01) 
	local pval = r(p)   
	outreg, merge(IV_FIRST) nod keep(${IV_qua}) ctitle(" ", "`l'")  ${option} addrows(  "$model_3"    \"F-stat", "`F'" \ "p-val", "`pval'" ) 
	
	local l  :  variable label pct_2010_sq 
	
	qui  reg pct_2010_sq   ${IV_qua}  i.id_country_yearess  $regional $control     if   sample_Z_pca_score  ==1 , cluster (id_nuts2)
	test ${IV_qua} 
	local F = round( r(F) ,0.01) 
	local pval = r(p)   
	outreg, merge(IV_FIRST) nod keep(${IV_qua}) ctitle(" ", "`l'")  ${option} addrows(  "$model_3"    \"F-stat", "`F'" \ "p-val", "`pval'" ) 
	
	*
	nois outreg,  replay(IV_FIRST)  $option    title(Table A.7)
	
******************************************************************************************************************************  	
***  Table A.8: Robustness Checks: Shift-Share instrument  
******************************************************************************************************************************  	
 		
	local j = 1
foreach y of varlist $Z_dependent    {

	local l  :  variable label `y'
	dis "`l'"
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1
	qui su `y'    if   `samplee'==1  
	local av = round(r(mean),0.01) 
 
	 foreach i in  qua {
	 
	 outreg, clear(IV_base_`i')
	 outreg, clear(IV_base_`i') 
	 
	 global m1 ${m2010_`i'}
	 global IV ${IV_`i'}
	
	qui  ivreg2  `y'  i.id_country_yearess     ( $m1  = $IV )  if   `samplee'==1   , cluster (id_nuts2)
	local F = round(e(widstat),0.01) 
	outreg, merge(IV_base_`i')  	 nod keep( $m1   ) ctitle(" ", "`l'")  ${option}  addrows(  "$model_1"    \"F-stat", "`F'")  
	
	qui   ivreg2  `y'  i.id_country_yearess  $regional   ( $m1  = $IV  )    if   `samplee'==1 , cluster (id_nuts2)
	local F = round(e(widstat),0.01) 
	outreg, merge(IV_base_`i')  	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows(  "$model_2"    \"F-stat", "`F'") 
	
	qui   ivreg2  `y'  i.id_country_yearess  $regional $control   ( $m1  =$IV  )   if   `samplee'==1 , cluster (id_nuts2)
	local F = round(e(widstat),0.01) 
	outreg, merge(IV_base_`i')  	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows(  "$model_3"    \"F-stat", "`F'") 
	
	qui  ivreg2  `y'   i.id_country_yearess $regional $control  $inc_control    ( $m1  =$IV )   if   `samplee'==1 , cluster (id_nuts2)
	local F = round(e(widstat),0.01) 
	outreg, merge(IV_base_`i') 	 nod keep( $m1   )  ctitle(" ", "")  ${option} addrows(  "$model_4"    \"F-stat", "`F'") 
	
	qui  ivreg2  `y'   i.id_country_yearess  $regional $control  $inc_control  $subview_control     ( $m1  =$IV )    if   `samplee'==1 ,    cluster (id_nuts2)
	local F = round(e(widstat),0.01) 
	outreg, merge(IV_base_`i') 	 nod keep( $m1   )  ctitle(" ", "")   ${option}  addrows(  "$model_5"    \"F-stat", "`F'") 
	
		
	 }
	local j = 1 + `j'
	}	   
	*

	nois outreg , replay(IV_base_qua)  $option    title(Table A.8)
	

	
	

******************************************************************************************************************************  	
****     Table A.9: Robustness Checks: Additional controls 	
******************************************************************************************************************************  	
			
		
	
local i = 1
foreach y of varlist $Z_dependent    {

	local l  :  variable label `y'
	dis "`l'"
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	qui su `y'    if   `samplee'==1  
	local av = round(r(mean),0.01) 
 
	foreach j in  qua {
	
	global m1  ${m2010_`j'}
	des  $m1
	
	outreg, clear(robust_spec_`j'_`i')
		
	 qui areg `y'   $m1  $regional  $control   $inc_control  $subview_control   if   `samplee'==1   , absorb(  id_country_yearess)   vce(cluster id_nuts2)
	  breakpoint_2010_`j'
	  outreg, merge(robust_spec_`j'_`i')	 nod keep(  $m1   ) ctitle(" ", "baseline ")  ${option} addrows("$model_5"  \ "breakpoint", $breakpoint )   
 
     qui areg `y'   $m1   $regional $control   $inc_control  $subview_control   if   `samplee'==1 & federation==0  , absorb(  id_country_yearess)  vce(cluster id_nuts2)
	  breakpoint_2010_`j'
	  outreg, merge(robust_spec_`j'_`i')	 nod keep(  $m1   ) ctitle(" ", "exl.Federation")  ${option} addrows( "$model_5"\ "breakpoint", $breakpoint )   
	
	qui areg `y'   $m1   $regional $control   $inc_control  $subview_control   if   `samplee'==1 & capitals ==0  , absorb(  id_country_yearess)   vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(robust_spec_`j'_`i') nod keep(  $m1   ) ctitle(" ", "exl.capitals")  ${option} addrows("$model_5" \ "breakpoint", $breakpoint )   
	
	qui areg `y'   $m1   $regional $control  $inc_control  $subview_control  GDP_growth_80_00   if   `samplee'==1   , absorb(  id_country_yearess)  vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(robust_spec_`j'_`i')	 nod keep(  $m1  GDP_growth_80_00   ) ctitle(" ", "long-term growth")  ${option} addrows("$model_5"\ "breakpoint", $breakpoint )   
	
	qui areg `y'   $m1   $regional $control  $inc_control  $subview_control    GDP_growth_65_00   if   `samplee'==1   , absorb(  id_country_yearess)   vce(cluster id_nuts2)
	  breakpoint_2010_`j'
	  outreg, merge(robust_spec_`j'_`i')	 nod keep(  $m1   GDP_growth_65_00   ) ctitle(" ", "long-term growth")  ${option} addrows("$model_5" \ "breakpoint", $breakpoint )  
	
	qui areg `y'   $m1   $regional $control  $inc_control  $subview_control    ln_import_shock07_91   if   `samplee'==1  , absorb(  id_country_yearess) vce(cluster id_nuts2)
	  breakpoint_2010_`j'
	  outreg, merge(robust_spec_`j'_`i')	 nod keep(  $m1 ln_import_shock07_91  ) ctitle(" ", "manuc")  ${option} addrows( "$model_5" \ "breakpoint", $breakpoint )   

	qui areg `y'   $m1   $regional $control   $inc_control  $subview_control  manufacturing_share  if   `samplee'==1  , absorb(  id_country_yearess)   vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(robust_spec_`j'_`i')	 nod keep(  $m1  manufacturing_share   ) ctitle(" ", "manuc")  ${option} addrows(  "$model_5" \ "breakpoint", $breakpoint )   
	
	qui areg `y'   $m1   $regional $control  $inc_control  $subview_control   ln_riskpoverty if   `samplee'==1  , absorb(  id_country_yearess)   vce(cluster id_nuts2)
	  breakpoint_2010_`j'
	  outreg, merge(robust_spec_`j'_`i')	 nod keep(  $m1   ln_riskpoverty  ) ctitle(" ", "poverty")  ${option} addrows(  "$model_5" \ "breakpoint", $breakpoint )  	
	
	qui areg `y'   $m1   $regional $control  $inc_control  $subview_control  ln_bed_percap2010_2015  if   `samplee'==1  , absorb(  id_country_yearess)   vce(cluster id_nuts2)
	  breakpoint_2010_`j'
	  outreg, merge(robust_spec_`j'_`i')	 nod keep(  $m1  ln_bed_percap2010_2015 ) ctitle(" ", "public good")  ${option} addrows(  "$model_5" \ "breakpoint", $breakpoint )  	
	
	}
	local i = 1 + `i'
	}
	*
	
	
	nois	outreg , replay(robust_spec_qua_1)   $option  title(Table A.9)
	

	

******************************************************************************************************************************  	
**** Table A.10: Robustness Checks: Attitudinal outcomes used to construct the index
******************************************************************************************************************************  	

global Z_dep_robust Z_redis_scale 	Z_support_incequal  Z_gvslvol Z_gvslvue Z_gvcldcr Z_sbstrec   Z_sbbsntx Z_sblazy  
											
outreg, clear(robustdep_qua_short)	

foreach y of varlist $Z_dep_robust   {

	local l  :  variable label `y'
	dis "`l'"
	
	tempvar  samplee 
	g  `samplee' = ess_sample ==1  & sample_Z_pca_score  ==1  
	
	
	qui su `y'    if   `samplee'==1  
	local av = round(r(mean),0.01) 
 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	

	global m1  ${m2010_qua}

	qui  `equa1' `y'  $m1  $regional $control   $inc_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_qua
	 outreg, merge(robustdep_qua_short)	 	 nod keep( $m1  ) ctitle(" ", "`l'")  ${option} addrows( "$model_4" \ "breakpoint", $breakpoint ) 
	
	}
*
	nois outreg ,  replay(robustdep_qua_short)  $option  title(Table A.10)


******************************************************************************************************************************  	
**** Table A.11: Robustness check: Additional outcomes (in 2016 survey round)
******************************************************************************************************************************  	


   qui reg Z_basinc $regional $control $inc_control  $subview_control 
	 g sample_Z_basinc= e(sample)
	qui reg Z_wrkprbf  $regional $control $inc_control  $subview_control 
	g sample_Z_wrkprbf= e(sample)
	
local i = 1
foreach y of varlist Z_wrkprbf Z_basinc   {

	local l  :  variable label `y'
	dis "`l'"
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 & sample_Z_pca_score ==1
	qui su `y'    if   `samplee'==1  
	local av = round(r(mean),0.01) 
 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	

	
	foreach j in qua {
	
	outreg, clear(base2_`j'_`i')	
	
	global m1  ${m2010_`j'}
	
	
	qui  `equa1' `y'    $m1      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_`j' 
	 outreg, merge(base2_`j'_`i') 	 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_1" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'    $m1  $regional      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(base2_`j'_`i')  	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_2" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'    $m1  $regional $control     if   `samplee'==1 ,     `equa2' vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(base2_`j'_`i')  	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_3" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'  $m1  $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(base2_`j'_`i')  	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_4" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'  $m1   $regional $control $inc_control  $subview_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(base2_`j'_`i') 	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_5" \ "breakpoint", $breakpoint )  
	
	}
	
	local i = 1 + `i'
	}	   
	*
	nois outreg,  replay(base2_qua_2)  $option    title(Table A.11)
	nois outreg,  replay(base2_qua_1)  $option     title(Table A.11)
	
	

	

******************************************************************************************************************************  	
**** Table A.12: Robustness check: Ordered Probit Specification
******************************************************************************************************************************  	


global  dep_robust  redis_scale support_incequal  gvslvol  gvslvue  gvcldcr  sbstrec  sbbsntx sblazy  
											
outreg, clear(robustdep_qua_oprobit)	

foreach y of varlist $dep_robust   {

	local l  :  variable label `y'
	
	tempvar  samplee 
	g  `samplee' = ess_sample ==1  & sample_Z_pca_score  ==1  
	
	qui su `y'    if   `samplee'==1  
	local av = round(r(mean),0.01) 
 
	local equa1 = "oprobit"
	
	global m1  ${m2010_qua}

	qui  `equa1' `y'  $m1  $regional $control  $inc_control i.id_country_yearess  if   `samplee'==1 ,       vce(cluster id_nuts2)
	qui breakpoint_2010_qua
	qui outreg, merge(robustdep_qua_oprobit)	  keep( $m1  ) ctitle(" ", "`l'")  ${option} addrows( "$model_4" \ "breakpoint", $breakpoint ) 
	
	}
*
	nois outreg,   replay(robustdep_qua_oprobit)  $option title(Table A.12)

	*
	
	
******************************************************************************************************************************  	
****   Table A.13: Robustness check: Sample of region with 200 ESS respondents or more	
******************************************************************************************************************************  	
	
	cap drop s N
	g s=  ess_sample ==1 & sample_Z_pca_score ==1
	bys nuts2 : egen N= total(s)
	
	local i = 1
foreach y of varlist $Z_dependent    {

	local l  :  variable label `y'
	dis "`l'"
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1  & N >200 
	qui su `y'    if   `samplee'==1  
	local av = round(r(mean),0.01) 
 
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	

	
	foreach j in qua {
	
	outreg, clear(robuN_`j'_`i')	
	
	global m1  ${m2010_`j'}
	
	
	qui  `equa1' `y'    $m1      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_`j' 
	 outreg, merge(robuN_`j'_`i') 	 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_1" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'    $m1  $regional      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(robuN_`j'_`i')  	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_2" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'    $m1  $regional $control     if   `samplee'==1 ,     `equa2' vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(robuN_`j'_`i')  	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_3" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'  $m1  $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(robuN_`j'_`i')  	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_4" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'  $m1   $regional $control $inc_control  $subview_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 breakpoint_2010_`j'
	 outreg, merge(robuN_`j'_`i') 	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_5" \ "breakpoint", $breakpoint )  
	
	}
	
	local i = 1 + `i'
	}	   
	*
	nois outreg , title(Table A.13)   replay(robuN_qua_1)  $option   
	 
	
	
******************************************************************************************************************************  	
****  Table A.15: Composition of immigrant stocks in High and Low Welfare States
******************************************************************************************************************************  	
	
	
 	global migrantvar compo_EU15 compo_A10 compo_middleEast compo_africa compo_america compo_asia immi_skill_ratio   rsc_mayda 

	 cap drop T 
	  cap drop c
	 g T= high_welfarestate
	 g c=1
	 local i=1
	 outreg,clear(WELF)
	 foreach v in $migrantvar  {
	 local l: variable label `v'
	  label var c "`l'"	  
	 label var T "`l'"	
	 
	  outreg,clear(a)
	 qui reg `v' c if high_welfarestate ==1 & sample_Z_pca_score ==1 , nocons vce(cluster id_nuts2)
	 qui outreg, merge(a) 	 keep(c)  varlabels tex plain fragment bdec(3)   nocenter nostars   stats(b)   summstat(N ) 	ctitle("","High Welfare")  addrows( "" ,"")
	 qui reg `v' c if high_welfarestate ==0 & sample_Z_pca_score ==1 , nocons vce(cluster id_nuts2)
	 qui outreg, merge(a) 	 keep(c)    varlabels tex plain fragment bdec(3)   nocenter nostars   stats(b)     summstat(N )	ctitle("","Low Welfare")   addrows( "" ,"") 
	 qui reg `v' T if  sample_Z_pca_score ==1 , vce(cluster id_nuts2)
	 qui outreg, merge(a) 	 keep(T)  ${option}   summstat(N ) 	  	ctitle("","Diff")   addrows( "" ,"") 
	
	 qui outreg ,  replay(a) ${option} store(elie_`i') 
	local i=1 +`i'
	}
	*
	 nois outreg ,  replay(elie_1) ${option} store(WELF) 
	forvalues i=2(1)8{
	  qui outreg ,  replay(WELF) ${option} append(elie_`i') 
	}
	*
	nois outreg ,  replay(WELF)  title(Table A.15) 
	
	
******************************************************************************************************************************  	
****  Table A.16: Explaining the stronger anti-redistribution effect of immigration in High Welfare State
******************************************************************************************************************************  	
	
	* Controling for difference in migrants' composition 

	foreach v in compo_A10 compo_middleEast  rsc_mayda {
	qui su `v' if ess_sample==1 & sample_Z_pca_score ==1
	g `v'_Z = (`v'-r(mean))/r(sd)
	
	}
	
	g compo_A10_for        = compo_A10_Z *pct_2010 
	g compo_middleEast_for = compo_middleEast_Z *pct_2010 
	g  rsc_mayda_for       = rsc_mayda_Z* pct_2010
		
	label var compo_A10_Z "sh.A10 origin among immi (Z-score)"
	label var compo_middleEast_Z "Middle East origin among immi (Z-score)"
	label var rsc_mayda_Z "RSC Mayda (Z-score)"
	label var compo_A10_for  "sh. A10 *sh. immi 2010" 
	label var  compo_middleEast_for  "sh. Middle East *sh. immi 2010" 
	label var rsc_mayda_for  "RSC *sh. immi 2010" 
	

	global m1  pct_2010  pct_2010_sq  high_WELF_for2010  
	global m2 $m1 compo_middleEast_Z  compo_middleEast_for 
	global m3 $m1   compo_middleEast_Z  compo_middleEast_for compo_A10_Z  compo_A10_for 
	global m4 $m3   rsc_mayda_Z  rsc_mayda_for 
	
	outreg, clear(WELF_compo) 
	foreach y of varlist $Z_dependent    {
	local l  :  variable label `y'
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	
	
	qui  `equa1' `y'  $m1   $regional $control $inc_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(WELF_compo) 	 nod keep( $m1  ) ctitle("`l'", "")  ${option} addrows( "$model_4"  )  	
	 
	qui  `equa1' `y'  $m2   $regional $control $inc_control   if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(WELF_compo) 	 nod keep( $m2  ) ctitle("`l'", "")  ${option} addrows( "$model_4"  )  	
	
	 qui `equa1' `y'  $m3   $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(WELF_compo) 	 nod keep( $m3  ) ctitle("`l'", "")  ${option} addrows( "$model_4" )  	
	
	 qui `equa1' `y'  $m4   $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(WELF_compo) 	 nod keep( $m4  ) ctitle("`l'", "")  ${option} addrows( "$model_4"  )  	
	}
	*
	nois outreg, replay(WELF_compo)    $option  title(Table A.16) 
	
	
******************************************************************************************************************************  	
****    Table A.17: Heterogeneous attitudinal response : at the Left, Center and Right of the political scale
******************************************************************************************************************************  	
	
	
	outreg, clear(robustideo)	
	local i = 1
	foreach y of varlist $Z_dependent    {
	local l  :  variable label `y'
	dis "`l'"
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	
	
	outreg, clear(robustideo_`j'_`i')	
	
	global m1   pct_2010  pct_2010_sq ideo1_for2010 ideo3_for2010 
	global addcontrol i.lrscale 
	
	qui  `equa1' `y'    $m1   $addcontrol   if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(robustideo)	 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_1" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'    $m1 $addcontrol  $regional      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(robustideo) 	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_2" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'    $m1 $addcontrol  $regional $control     if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(robustideo)	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_3" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'  $m1 $addcontrol  $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(robustideo) 	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_4" \ "breakpoint", $breakpoint ) 
	  
	qui  `equa1' `y'  $m1  $addcontrol   $regional $control $inc_control  $subview_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(robustideo)	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_5" \ "breakpoint", $breakpoint )  	
		local i= `i' +1 
		
	}
	*
	nois outreg,  replay(robustideo)   $option title(Table A.17) 
	
******************************************************************************************************************************  	
****    Table A.18: The heterogeneity in attitudinal response across political affiliation is not explained by differences in income and education
******************************************************************************************************************************  	

	global m1   pct_2010  pct_2010_sq  leftist_for2010      edusimple3_for2010        quant_hhincome1_for2010   quant_hhincome5_for2010    
	global m2  ${m1}  immi_bad_life1_for2010  
	global m3  ${m1}  immi_NOrightsoc1_for2010   
	global m4  ${m1}   immi_bad_life1_for2010  immi_NOrightsoc1_for2010   
		   
	global control_accounting i.lrscale  i.edusimple  immi_bad_life immi_NOrightsoc
	
	outreg, clear(accountIDEO)	
	local i = 1
	foreach y of varlist $Z_dependent  {

	local l  :  variable label `y'
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 

	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	
	
	foreach k  in 1 2  3 4 {
	qui  `equa1' `y'    ${m`k'}  $regional $control $inc_control  $subview_control 	${control_accounting}      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	outreg, merge(accountIDEO)		 nod keep(  ${m`k'}   ) ctitle("`l'", "")  ${option} addrows( "$model_5" )   			
	}
		local i= `i' +1 	
	}
	*
	nois outreg,  replay(accountIDEO)   $option title(Table A.18) 

	
******************************************************************************************************************************  	
****    Table A.19: Heterogeneity: survey round of ESS
******************************************************************************************************************************  	

	cap drop year2016_for2010 
	g year2016_for2010  = (year_ess==2016)   *pct_2010  
	label var year2016_for2010  "year 2016* sh immi 2010"
		
	outreg, clear(yearESS) 
	local i = 1
	foreach y of varlist $Z_dependent    {
	local l  :  variable label `y'
	dis "`l'"
	tempvar  samplee 
	g  `samplee' = ess_sample ==1 & sample_`y'==1 
	
	local equa1 = "areg"
	local equa2 = "absorb( id_country_yearess )"	

	global m1 pct_2010  pct_2010_sq   year2016_for2010 
	
	qui  `equa1' `y'    $m1      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(yearESS)	 nod keep( $m1   ) ctitle(" ", "`l'")  ${option} addrows( "$model_1"  ) 
	  
	qui  `equa1' `y'    $m1  $regional      if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(yearESS)	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_2" ) 
	  
	qui  `equa1' `y'    $m1  $regional $control     if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(yearESS)	 nod keep( $m1   ) ctitle(" ", "")  ${option} addrows( "$model_3"  ) 
	  
	qui  `equa1' `y'  $m1  $regional $control $inc_control    if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(yearESS) 	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_4"  ) 
	  
	qui  `equa1' `y'  $m1   $regional $control $inc_control  $subview_control  if   `samplee'==1 ,     `equa2'  vce(cluster id_nuts2)
	 outreg, merge(yearESS)	 nod keep( $m1  ) ctitle(" ", "")  ${option} addrows( "$model_5")  	
		local i= `i' +1 
		
	}
	*
	nois outreg, replay(yearESS)   $option title(Table A.19) 
